from django.contrib.auth.models import Group,Permission
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serializers.groups import GroupSerializer
from meiduo_admin.utils import PageNum

from meiduo_admin.serializers.permission import PermissionSerializer


class GroupsView(ModelViewSet):
    # 指定查询集
    queryset = Group.objects.all()
    # 指定序列化器
    serializer_class = GroupSerializer
    # 指定分页器
    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    def simple(self,request):
        pers = Permission.objects.all()
        ser = PermissionSerializer(pers,many=True)
        return Response(ser.data)
